package com.psd.demo.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pds.demo.dao.OrganizationDao;
import com.pds.demo.dao.impl.OrganizationDaoImpl;
import com.pds.mvc.ActionForward;
import com.pds.mvc.Actions;
import com.psd.demo.common.Page;
import com.psd.demo.model.OrgAllList;

public class DepListServlet extends Actions {

	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {

		// 告诉服务器，对表单进行中文解码

		response.setContentType("text/html;charset=utf-8");
		OrganizationDao dao = new OrganizationDaoImpl();
		try {
			// get pageNo from jsp when you click nextpage or prepage or
			// firstpage
			int pageNo = this.getParameterStringForInteger("pageNo", request);
			// get all count of list
			int totalCount = dao.getDepListCount();
			Page page = new Page(totalCount);
			page.setCurrentPage(pageNo);
			List<OrgAllList> depuserlist = dao.selectAllDepList(
					(page.getCurrentPage() - 1) * page.getPageSize(),
					page.getPageSize());
			// set your list to jsp page
			this.setRequestPage("depuserlist", depuserlist, request);
			// set your page tag to jsp page .
			// you can import c:out on your jsp and escapeXml must be false.
			this.setRequestPage("depPage", page.getHTML(request), request);

		} catch (Exception e) {
			e.printStackTrace();
		}

		return new ActionForward("./deplist.jsp", true);
	}

}
